class NetflowHandler
   def initialize(address, port=5555)
       @address = address
       @port    = port 
   end

   def get_default_bars
       ["src_address", "src_port", "dst_port", "dst_address"]
   end

   def run()
       server = UDPSocket.open
       server.bind(@address, @port)

       puts "[NetflowHandler] entering udp read loop"

       while header = server.read(24)
           netflow_header = BitStruct.parse( header, NetFlow_Header_V7).first

           netflow_header.count.times do |i|
               tmp_netflow_record = BitStruct.parse( server.read(52), NetFlow_Record_V7 ).first
               conn = NetflowConnection.new(Time.now, tmp_netflow_record) 
               $connections.add_or_update( conn )
           end
           puts "[NetflowHandler] parsed %d records" % netflow_header.count
       end
   end
end
